# Big memory related functions
library(bigmemory)
library(biganalytics)

# To scale for each column do the following
# 1) Subtract the column mean
# 2) Divide by the standard deviation
big.scale = function(ts.mat) {
    ts.colmean = colmean(ts.mat)
    ts.colsd = colsd(ts.mat)
    
    for (i in 1:ncol(ts.mat))
        ts.mat[,i] = (ts.mat[,i] - ts.colmean[i])/ts.colsd[i]
    
    return(ts.mat)
}

small.scale = function(ts.mat) {
    ts.colmean = apply(ts.mat, 2, mean)
    ts.colsd = apply(ts.mat, 2, sd)
    
    for (i in 1:ncol(ts.mat))
        ts.mat[,i] = (ts.mat[,i] - ts.colmean[i])/ts.colsd[i]
    
    return(ts.mat)
}